//泛型
function createArray(length: number, value: any): Array<any> {
  let result = [];
  for (let i = 0; i < length; i++) {
    result[i] = value;
  }
  return result;
}

function createArray2<T>(length: number, value: T): Array<T> {
  let result: T[] = [];
  return result;
}

function swap<T, U>(tuple: [T, U]): [U, T] {
  return [tuple[1], tuple[0]];
}

//泛型约束
interface lengthwise {
  length: number;
}

function loggingIdentify<T extends lengthwise>(arg: T): T {
  return arg;
}

function copyFields<T extends U, U>(target: T, source: U): T {
  for (let id in source) {
    target[id] = (<T>source)[id];
  }
  return target;
}
